﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Ivi.Visa;
using NationalInstruments.Visa;
using Model;
using Common;
using System.IO;

namespace AutoTestKeySight4990
{
    public partial class MainFrm : Form
    {
        ResourceManager rm = new ResourceManager();
        MessageBasedSession session;
        IMessageBasedRawIO HandleIO;
        //TestItem[] testItems= null;
        string rmstring = null;
        public MainFrm()
        {
            InitializeComponent();
        }

        private void comboBox1_DropDown(object sender, EventArgs e)
        {
            comboBox1.Items.Clear();
            string [] ad =(string[])rm.Find("?*INSTR");
            foreach (string s in ad)
            {
                comboBox1.Items.Add(s); 
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            session =(MessageBasedSession) rm.Open(rmstring);
            HandleIO = session.RawIO;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            HandleIO.Write(textBox1.Text);
            
           // label1.Text = HandleIO.ReadString();

        }

        private void button3_Click(object sender, EventArgs e)
        {
            
            
            HandleIO.Write(textBox1.Text);
            richTextBox1.Text = HandleIO.ReadString();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            session.Dispose();
        }

        private void MainFrm_Load(object sender, EventArgs e)
        {
            rmstring = ConfigHelper.ReadIni("PORT", "rmPort", "TCPIP0::K-E4990A-03629.local::inst0::INSTR",50);
        }
    }
}
